/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jsf.beans.admin;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.DateFormat;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import manager.FeedbackManager;
import model.admin.Feedback;

/**
 *
 * @author Administrator
 */
@ManagedBean
@RequestScoped
public class FeedBackBean {

    private int feebackId;
    private String name;
    private String email;
    private String feebackTitle;
    private String feebackText;
    private Date createdTime;
    private int feedbackStatus;

    public FeedBackBean() {
    }

    public FeedBackBean(int feebackId, String name, String email, String feebackTitle, String feebackText, Date createdTime, int feedbackStatus) {
        this.feebackId = feebackId;
        this.name = name;
        this.email = email;
        this.feebackTitle = feebackTitle;
        this.feebackText = feebackText;
        this.createdTime = createdTime;
        this.feedbackStatus = feedbackStatus;
    }

    public int getFeebackId() {
        return feebackId;
    }

    public void setFeebackId(int feebackId) {
        this.feebackId = feebackId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFeebackTitle() {
        return feebackTitle;
    }

    public void setFeebackTitle(String feebackTitle) {
        this.feebackTitle = feebackTitle;
    }

    public String getFeebackText() {
        return feebackText;
    }

    public void setFeebackText(String feebackText) {
        this.feebackText = feebackText;
    }

    public Date getCreatedTime() {
        return createdTime;
    }

    public void setCreatedTime(Date createdTime) {
        this.createdTime = createdTime;
    }

    public int getFeedbackStatus() {
        return feedbackStatus;
    }

    public void setFeedbackStatus(int feedbackStatus) {
        this.feedbackStatus = feedbackStatus;
    }

    public List<Feedback> loadData() {
        FeedbackManager fm = new FeedbackManager();
        return fm.getAll();
    }

    public String edit(int id) {
        return "updatefeedback.jsp";
    }

    public String insert() {
        java.util.Date date = new java.util.Date();
//        Feedback f = new Feedback(feedbackID, accountID, feedbackText, new Date(date.getTime()), feedbackStatus == true ? 1 : 0);
        Feedback f = new Feedback(feebackId, name, email, feebackTitle, feebackText, new Date(date.getTime()), feedbackStatus);
        FeedbackManager mana = new FeedbackManager();
        boolean flag = mana.insert(f);
        if (flag) {
            loadData();
            return "FeedbackManager.xhtml";
        }
        return "";
    }

//    public String edit(int id) {
//        java.util.Date date = new java.util.Date();
//        Feedback f = new Feedback(feedbackID,accountID,feedbackText, new Date(date.getTime()),feedbackStatus == true ? 1 : 0);
//        FeedbackManager mana = new FeedbackManager();
//        boolean result = mana.update(f);
//        return "feedback.jsp";
//       
//    }
    public void delete(int id) {

        FeedbackManager mana = new FeedbackManager();
        mana.delete(id);
        loadData();
    }

    public boolean convertBoolean(int value) {
        return value == 1 ? true : false;
    }

    public void reset() {
        java.util.Date date = new java.util.Date();
        this.name = "";
        this.email = "";
        this.feebackTitle = "";
        this.feebackText = "";
        this.createdTime = new Date(date.getTime());
        this.feedbackStatus = 0;

    }
}
